/**
 * 
 */
package org.youisoft.summer.evaluator.operator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.operator.base.NumberOperator;
import org.youisoft.summer.evaluator.operator.base.StringOperator;

/**
 * @author zijiang.jl
 *
 */
public abstract class AbstractOperator<T> implements Operator<T> {
	protected static final Log logger=LogFactory.getLog(Operator.class);
	private T value;

	public AbstractOperator(){
		
	}
	public AbstractOperator(T value){
		this.value=value;
	}
	
	public final T value() {
		return value;
	}

	public final Operator<T> setValue(T value) {
		this.value = value;
		return this;
	}
	
	

	@Override
	public <C, R, P> Operator<?> prepareCall(CalContext<C, R, P> context) {
		return this;
	}
	
	@Override
	public <C, R, P> Operator<?> postCall(CalContext<C, R, P> context) {
		return this;
	}
	
	
	
	//===========================================

	@Override
	public NumberOperator convertToNumberOperator() {
		throw new RuntimeException("Operator is not support");
	}
	@Override
	public StringOperator convertToStringOperator() {
		throw new RuntimeException("Operator is not support");
	}
	@Override
	public int hashCode() {
		if(this.value!=null) return this.value().hashCode();
		return 0;
	}


	@Override
	public boolean equals(Object obj) {
		if(obj==this) return true;
		if(!(obj instanceof Operator<?>)) return false;
		Operator<?> op=(Operator<?>)obj;
		if(this.getClass().getName().equals(op.getClass().getName())
				&&this.value().equals(op.value())) return true;
		return super.equals(obj);
	}
}
